package gloompc;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.io.Serializable;
import java.util.ArrayList;

/**
 *
 * @author Marcus Berger 3B
 */
public class SuperCard implements Serializable{
String name = null;
    int id;                                 //Name
    byte owner;                             // the player original owner of of the card
    byte controller;                        // the player that's in controll of the card
    boolean type[] = new boolean[TYPES];    // Types
    ArrayList<String> subtype = new ArrayList<String>(); // Subtypes
    String rarity;                                       // what rank of self-worth score
    ArrayList<Ability> abilities = new ArrayList<Ability>(); // Activated card text Abilities
    ArrayList<Ability>[] events = new ArrayList[EVENTS]; // Event cards ability
    ArrayList<Ability> statics = new ArrayList();       // static abilitys
    boolean basic;                                      // basic card
    SuperCard original;                                 // original card
    transient Image image = Images.noimage.getScaledInstance(240, 340, Image.SCALE_SMOOTH); //
    boolean sickness = false;                               // continuing damage
    boolean blocked = false;                                // a card is blocked either by another card or card abillity
    boolean tapped = false;                                 // the card is tapped by either a card or death
    boolean dead = false;                                   // killd by the use of an untimly death card
    byte turns = 0;                                         // turns in a match 1-2
    boolean attack1 = false;                                //first inflict on selfworth score
    boolean attack2 = true;                                 //second inflict on selfworth score
    int SelfworthScore01 = 0;                               //Gloom point system for low type
    int SelfworthScore02 = 0;                               //Gloom point system for middle type
    int SelfworthScore03 = 0;                               //Gloom point system for high type

    public byte getSelfworthScore01() {                                
        return (byte) (SelfworthScore01 + counter[plus] - counter[minus]); // calculation of the low selfworth score
    }

    public byte getSelfworthScore02() {                                
        return (byte) (SelfworthScore02 + counter[plus] - counter[minus]); // calculation of the middle selfworth score
    }

    public byte getSelfworthScore03() {                            
        return (byte) (SelfworthScore03 + counter[plus] - counter[minus]); // calculation of the high selfworth score
    }
    byte x = 0;                                     
    CardList equippedWith = new CardList();                 //Positive
    CardList attachedWith = new CardList();                 //Negative
    byte prevZone = deck;                                   // the previus zone the card was in
    byte zone = deck;                                       // the zone the card is in
    boolean targeted;                                       // the target of a card
    byte prevent = 0;                                       //prevent card
    byte prevented = 0;                                     //prevented card
    byte redirect = 0;                                      //move modifyer card
    byte redirected = 0;                                    //moved modifyer card
    SuperCard[] redirectTo = null;                          // 
    byte affectonSWS = 0;                                   // the cards affect on the selfworth score
    byte[] counter = new byte[COUNTERS];                    //Self-worth gloom
    boolean[] protection = new boolean[6];                  //you can't put certain cards ontop of a card
    boolean unblockable = false;                            // you can't stop this card from being played
    boolean nogo = false;                                   // you can't play certain cards when this cards ability is displayed

    /**
     * 
     */
    public SuperCard() {
        init();
    }
    /**
     * 
     */
    public SuperCard(String n) {
        name = n;
        init();
    }

    /**
     * initation
     */
    public void init() {
        for (ArrayList<Ability> a : events) {
            a = new ArrayList<Ability>();
        }
    }
    /**
     * /--/
     */
    public void initImg() {
        image = Images.getCard(this);
    }
    /**
     * /--/
     */
    void init(byte player) {
        owner = player;
        original = getValues();
    }
    /**
     * certain cards can't be put on this card
     */
    public boolean target(SuperCard card) {
        return !untargeted && !hasProtectionFrom(card);
    }
    /**
     * the card gives protection from certian types of cards and you cant't play a certain card while this card is in play
     */
    public boolean hasProtectionFrom(SuperCard c) {
        for (int i = 1; i < TYPES; i++) {
            if (c.cast.cost[i] > 0 && protection[i]) {
                return t§rue;
            }
        }
        return false;
    }
    /**
     * moves card to a different zone
     */
    public void moveTo(byte zone) {
        this.zone = zone;
    }
    /**
     * Creates copies of the cards
     */
    public SuperCard getValues() {
        SuperCard copy = new SuperCard();
        copy.id = id;
        copy.name = name;
        copy.owner = owner;
        copy.basic = basic;
        copy.type = type;
        copy.subtype = subtype;
        copy.rarity = rarity;
        copy.abilities = abilities;
        copy.events = events;
        copy.statics = statics;

        return copy;
    }
    /**
     * gets the rarity value
     */
    public int getRarityValue() {
        if (rarity.equalsIgnoreCase("Low")) {
            return 0;
        } else if (rarity.equalsIgnoreCase("Middle")) {
            return 1;
        } else if (rarity.equalsIgnoreCase("High")) {
            return 2;
        }
        return -1;
    }
    /**
     * Creates the card garphicaly
     */
    public void draw(Graphics g, int x, int y, int w, int h, boolean highlight) {

        boolean darken = false;
        Image img = Images.back;
        if (!facedown) {
            img = image;
            darken = marked;
        }

        if (highlight) {
            g.drawImage(Images.highlight, x - SpelPlan.cardSpace, y - SpelPlan.cardSpace, w + SpelPlan.cardSpace * 2, h + SpelPlan.cardSpace * 2, null);
        }
        g.setColor(Color.black);
        g.fillRect(x, y, w, h);
        if (img != null) {
            if(img!=Images.noimage){
            g.drawImage(img, x, y, w, h, null);
            }else{
                g.setColor(Color.white);
                g.drawString(name, x+h/2, y);
            }
            if (darken) {
                g.drawImage(Images.overlay, x, y, w, h, null);
            }
        }
    }
    /**
     * draws the cards coordinates
     */
    public void draw(Graphics g, Rectangle r,boolean h) {
        draw(g, (int) r.getX(), (int) r.getY(), (int) r.getWidth(), (int) r.getHeight(),h);
    }
}